﻿#region Used Namespaces

using System;
using ContactPrinter.Model.Interfaces;
using Google.GData.Extensions;

#endregion

namespace ContactPrinter.Model
{
    public class GoogleName : IName
    {
        private readonly Name name;

        public GoogleName(Name name)
        {
            this.name = name;
        }

        #region Implementation of IName

        public string DisplayedName
        {
            get
            {
                if (!string.IsNullOrEmpty(FamilyName))
                {
                    if (!string.IsNullOrEmpty(GivenName))
                    {
                        return string.Format("{0}, {1}", FamilyName, GivenName);
                    }
                    return FamilyName;
                }
                return GivenName;
            }
        }

        public string GivenName
        {
            get { return name.GivenName; }
            set { name.GivenName = value; }
        }

        public string GivenNamePhonetics
        {
            get { return name.GivenNamePhonetics; }
            set { name.GivenNamePhonetics = value; }
        }

        public string AdditionalName
        {
            get { return name.AdditionalName; }
            set { name.AdditionalName = value; }
        }

        public string AdditionalNamePhonetics
        {
            get { return name.AdditionalNamePhonetics; }
            set { name.AdditionalNamePhonetics = value; }
        }

        public string FamilyName
        {
            get { return name.FamilyName; }
            set { name.FamilyName = value; }
        }

        public string FamilyNamePhonetics
        {
            get { return name.FamilyNamePhonetics; }
            set { name.FamilyNamePhonetics = value; }
        }

        public string NamePrefix
        {
            get { return name.NamePrefix; }
            set { name.NamePrefix = value; }
        }

        public string NameSuffix
        {
            get { return name.NameSuffix; }
            set { name.NameSuffix = value; }
        }

        public string FullName
        {
            get { return name.FullName; }
            set { name.FullName = value; }
        }

        #endregion

        public override string ToString()
        {
            return string.Format("{0}, {1}", FamilyName, GivenName);
        }

        public int CompareTo(object obj)
        {
            var otherName = obj as IName;
            if (otherName == null)
                throw new ArgumentException("Object is not a IName");

            return String.Compare(DisplayedName, otherName.DisplayedName, StringComparison.InvariantCultureIgnoreCase);
        }
    }
}